//栈_比较含退格的字符串
//https://leetcode.cn/problems/backspace-string-compare/description/
public class Test {
    public static void main(String[] args) {
        //
    }
}

class Solution1 {
    public boolean backspaceCompare(String s1, String t1) {
        StringBuffer s = new StringBuffer();
        StringBuffer t = new StringBuffer();
        for (int i = 0; i < s1.length(); i++) {
            char c = s1.charAt(i);
            if (c == '#') {//这里写的有点复杂了，其实逻辑可以更简单些的
                if (s.length() <= 0) {
                    continue;
                } else {
                    s.deleteCharAt(s.length() - 1);
                }

            }else{
                s.append(c);
            }
        }
        for (int i = 0; i < t1.length(); i++) {
            char c = t1.charAt(i);
            if (c == '#') {//这里写的有点复杂了，其实逻辑可以更简单些的
                if (t.length() <= 0) {
                    continue;
                } else {
                    s.deleteCharAt(t.length() - 1);
                }

            }else{
                t.append(c);
            }
        }
        return s.toString().equals(t.toString());

    }
}
class Solution {
    public boolean backspaceCompare(String s1, String t1) {
        return func(s1).equals(func(t1));
    }

    private String func(String s1) {
        StringBuffer s = new StringBuffer();
        for (int i = 0; i < s1.length(); i++) {
            char c = s1.charAt(i);
            if (c != '#') {
                s.append(c);
            }else{
                if (s.length() > 0) {
                    s.deleteCharAt(s.length() - 1);
                }
            }
        }
        return s.toString();
    }
}